//
//  BaseViewModel.swift
//  LookingForRoom
//
//  Created by 🐑 on 2019/1/7.
//  Copyright © 2019 Zhu. All rights reserved.
//

//import Foundation

class BaseViewModel {
    
    enum DataStatus {
        
        case initial
        case load
        case hasData
        case noData
        case failed
        case error
    }
    
    // MARK: - 成员变量
    // MARK: 公共
    open var dataStatus: DataStatus = .initial
    
    // MARK: - 方法
    // MARK: 公共
    /// 保持旧数据可变状态
    open func keepDataNextStatus(status: DataStatus) {
        switch dataStatus {
        case .initial:
            guard status == .load else { return }
            dataStatus = status
        case .load:
            guard (status == .hasData) || (status == .noData) || (status == .failed) || (status == .error) else { return }
            dataStatus = status
        case .hasData, .noData:
            guard (status == .hasData) || (status == .noData) else { return }
            dataStatus = status
        case .failed, .error:
            guard (status == .hasData) || (status == .noData) || (status == .failed) || (status == .error) else { return }
            dataStatus = status
        }
    }
}
